<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap.css" />
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap-responsive.css" />
    <link rel="stylesheet" type="text/css" href="../Css/style.css" />
    <script type="text/javascript" src="../Js/jquery.js"></script>
    <script type="text/javascript" src="../Js/jquery.sorted.js"></script>
    <script type="text/javascript" src="../Js/bootstrap.js"></script>
    <script type="text/javascript" src="../Js/ckform.js"></script>
    <script type="text/javascript" src="../Js/common.js"></script>
    <script>
    $(function () {
        $(':checkbox[name="group[]"]').click(function () {
            $(':checkbox', $(this).closest('li')).prop('checked', this.checked);
        });
		$('#backid').click(function(){
				window.location.href="role_index.jsp";
		 });
    });
    function addSubmit(){
    	var name_=$("input[name='roleName']").val();
    	if(name_==null||name_.trim()==""){
    		alert("角色名字不能为空");
    		return;
    	}else if($("radio[name='roleState']").val()){
    		alert("请选择状态");
    		return;
    	}
    	$.ajax({
    		url:'<%=basePath%>RoleServlet',
			data:$("#actionForm").serialize(),
			type:"post",
			dataType:"json",
			success:function(data){
				if(data.message!=null){
					if(data.message>0){
						alert("成功添加"+data.message+"条数据");
						location.href="role_index.jsp";
					}
				}
			}
    	});
    }
</script>
    <style type="text/css">body { padding-bottom: 40px;} .sidebar-nav {  padding: 9px 0; }@media (max-width: 980px) {
            /* Enable use of floated navbar text */.navbar-text.pull-right 
            { float: none; padding-left: 5px; padding-right: 5px;}}
    </style>
</head>
<body>
<form action="RoleServlet" method="post" id="actionForm" class="definewidth m20" >
	<input type="hidden" name="oper" value="ADD"/>
	<table class="table table-bordered table-hover  m10" id="info" >
		<thead>
	    <tr>
	        <td width="10%" class="tableleft">名称</td>
	        <td ><input type="text" name="roleName" /></td>
	    </tr>
	    <tr>
	        <td width="10%" class="tableleft">描述</td>
	        <td ><textarea name="roleDes"></textarea></td>
	    </tr>
	    <tr>
	        <td width="10%" class="tableleft">状态</td>
	        <td id="status">
	            <input type="radio" name="roleState" value="1" checked="checked" /> 启用
	            <input type="radio" name="roleState" value="0"  />禁用
	        </td>
	        
	    </tr>
		</thead>
		<tbody id="tbody">
		 <tr>
	        <td class="tableleft">权限</td>
	        <td>
		        <ul>
			        <li>
				        <label class='checkbox inline'>
				        <input type='checkbox' name='group[]' value='' />公用节点</label>
				        <ul>
					        <li>
						        <label class='checkbox inline'>
						        <input type='checkbox' name='node[]' value='21' checked/>省市区级联数据</label>
					        </li>
					        <li>
						        <label class='checkbox inline'>
						        <input type='checkbox' name='node[]' value='22' checked/>省市区数据获取</label>
				        	</li>
				        </ul>
			        </li>
			        <li>
				        <label class='checkbox inline'>
				        <input type='checkbox' name='group[]' value='' />权限</label>
				    <ul>
				        <li>
					        <label class='checkbox inline'>
					        <input type='checkbox' name='node[]' value='1' checked/>权限列表</label>
				        </li>
				        <li>
				        	<label class='checkbox inline'>
				        	<input type='checkbox' name='node[]' value='2' checked/>权限添加</label>
				        </li>
				        <li>
				        	<label class='checkbox inline'>
				        	<input type='checkbox' name='node[]' value='3' checked/>权限编辑</label>
				        </li>
				        <li>
				        	<label class='checkbox inline'>
				        	<input type='checkbox' name='node[]' value='4' checked/>权限删除</label>
				        </li>
			        </ul>
		        </li>
		        <li>
			        <label class='checkbox inline'>
			        <input type='checkbox' name='group[]' value='' />用户</label>
			        <ul>
				        <li>
					        <label class='checkbox inline'>
					        <input type='checkbox' name='node[]' value='9' checked/>用户列表</label>
				        </li>
				        <li>
					        <label class='checkbox inline'>
					        <input type='checkbox' name='node[]' value='10' checked/>用户添加</label>
				        </li>
				        <li>
					        <label class='checkbox inline'>
					        <input type='checkbox' name='node[]' value='11' checked/>用户编辑</label>
				        </li>
				        <li>
					        <label class='checkbox inline'>
					        <input type='checkbox' name='node[]' value='12' checked/>用户删除</label>
			        	</li>
			        </ul>
		        </li>
		        <li>
			        <label class='checkbox inline'>
			        <input type='checkbox' name='group[]' value='' />菜单管理</label>
			        <ul>
				        <li>
				        	<label class='checkbox inline'>
				        	<input type='checkbox' name='node[]' value='13' checked/>菜单列表</label>
				        </li>
				        <li>
					        <label class='checkbox inline'>
					        <input type='checkbox' name='node[]' value='14' checked/>菜单新增</label>
				        </li>
				        <li>
				       		<label class='checkbox inline'>
				        	<input type='checkbox' name='node[]' value='15' checked/>菜单编辑</label>
				        </li>
				        <li>
					        <label class='checkbox inline'>
					        <input type='checkbox' name='node[]' value='16' checked/>菜单删除</label>
			        	</li>
			        </ul>
		        </li>
		        <li>
			        <label class='checkbox inline'>
			        <input type='checkbox' name='group[]' value='' />角色</label>
			        <ul>
				        <li>
				        	<label class='checkbox inline'>
				        	<input type='checkbox' name='node[]' value='5' checked/>角色列表</label>
			        	</li>
			        	<li>
			        		<label class='checkbox inline'>
			       			<input type='checkbox' name='node[]' value='6' checked/>角色添加</label>
			        	</li>
			        	<li>
			        		<label class='checkbox inline'>
			        		<input type='checkbox' name='node[]' value='7' checked/>角色编辑</label>
			        	</li>
			        	<li>
			        		<label class='checkbox inline'>
			        		<input type='checkbox' name='node[]' value='8' checked/>角色删除</label>
			        	</li>
			        </ul>
		        </li>
		        </ul>
	        </td>
	    </tr>
		</tbody>
		<tfoot id="tfoot" >
		<tr>
	    	<td colspan="2">
	    		<input type="button" class="btn btn-primary" name="save"  id="save" value="保存 " onclick="addSubmit()"/>&nbsp;&nbsp;
	            <input type="button" class="btn btn-success" name="backid" id="backid" value="返回列表"/>
	        </td>
	    </tr>
		</tfoot>
	</table>
</body>
</html>